$(function(){
     
    $("#form_cadastro").validate({
            //submitHandler: function(form) {
            //    $("#form_cadastro").submit();
            //},
            onfocusout: function (element) {
                $(element).valid();
            },
            rules: {
                    
                    cad_email: { required: true, email: true},
                    cad_email2: { required: true, email: true, equalTo: "#cad_email" },
                    cad_senha: { required: true, minlength: 6 },
                    confirm_password: { required: true, minlength: 6, equalTo: "#cad_senha2" },
            },

    });
    $('#cad_email').blur(function(){
        $.post(URLBASE+'/'+CONTROL+'/valemail', { email: $('#cad_email').val() }, function(data){                  
            if(!data.ok)
            {
                alert(data.msg);
                $('#cad_email').focus();
            }   
        }, 'json');
    });
    
    $('#cad_login').blur(function(){
        $.post(URLBASE+'/'+CONTROL+'/vallogin', { login: $('#cad_login').val() }, function(data){                  
            if(!data.ok)
            {
                alert(data.msg);
                $('#cad_login').focus();  
            } 
            
        }, 'json');
    });
    
});

jQuery(function($){
    $('#cad_tel').mask('(99) 9999-9999');    
    $('#cad_cpf').mask('999.999.999-99');
    $('#cad_cep').mask('99999-999');
    $('#cad_datnasc').mask('99/99/9999');
});